<?php
	 $root_dir = realpath(dirname(__FILE__));
    include_once($root_dir."/config/config.php");
    define('APP_DIR',ROOT_DIR."/app/");
    include_once(APP_DIR."/base/defined.php");
    
    require(ROOT_DIR.'/app/base/kernel.php');
    if(!kernel::register_autoload()){
        require(APP_DIR.'/base/autoload.php');
    }

		$db = kernel::database();
		$sql = "select * from sdb_tbdata_hellomoto where id>6599";

		$db_rs = $db->exec($sql);
		$rs = $db_rs['rs'];

		$i = 0;

 		$base_url = 'http://s.etao.com';
        $http = kernel::single('base_httpclient');
		while($product = mysql_fetch_assoc($rs)){


			$html = tbdata_html_object::str_get_html(base64_decode($product['content']));

			$a = $html->find('a.bj-btn',0);
			if(!$a) continue;
			$target_url = $base_url.$a->href;
			$html = $http->get($target_url);

			if(!$html) continue;
			$sql = "update sdb_tbdata_hellomoto set content2='".base64_encode($html)."' where id=".$product['id'];

			if($i++%10==0) echo $i."\n";
			$db->exec($sql);
		}